package org.bonorsoft.modules.wechat.controller;


import lombok.extern.slf4j.Slf4j;
import org.bonorsoft.common.system.vo.DictModel;
import org.bonorsoft.modules.system.entity.SysDictItem;
import org.bonorsoft.modules.system.framework.web.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/wechat/dict")
public class WxDictController {
    @Autowired
    private DictService dictService;

    /**
     * 获取字典键值
     * @param req
     * @return
     */
    @GetMapping("/getValues")
    @ResponseBody
    public Map<String,List<SysDictItem>> getValueByCode(HttpServletRequest req){
        Map<String,List<SysDictItem>> map = new HashMap<>();
        String values = req.getParameter("values");
        String[] split;
        if(values.contains(",")){
             split = values.split(",");
        }else {
            split = new String[]{values};
        }
        for (String value : split) {
            List<SysDictItem> paramValue = dictService.getParamValue(value);
            map.put(value,paramValue);
        }
        return map;
    }
}
